<template>
    <view class="container">
        <header-bar :config="config"></header-bar>
        <oreder-header @searchFn="searchFn" @doFilter="doFilter"></oreder-header>
        <view class="main">
            <mescroll-uni
                v-if="loadOk"
                ref="mescrollRef"
                @init="mescrollInit"
                :height="listHeight"
                :down="downOption"
                @down="refresh"
                :up="upOption"
                @up="getData">
                <order-item :key="index" v-for="(item, index) in datas" :data="item"></order-item>
            </mescroll-uni>
        </view>
        <view> </view>
    </view>
</template>

<script>
import orederHeader from "@/pages_shop/components/order/order-header.vue"
import orderItem from "@/pages_shop/components/return/return-order-item.vue"
import { getElementHeight } from "@/uni-sub-base/utils/elementUtil.js"
import { GetOrderPage } from "@/service/api/order.js"
export default {
    components: {
        orederHeader,
        "order-item": orderItem,
    },
    data() {
        return {
            config: {
                title: "订单选择",
                centerSlot: true,
            },
            listHeight: "", //list所需高度
            loadOk: false,
            datas: [],
            requestData: {
                endTime: "",
                PostType: "0,1,2,5",
                startTime: "",
                searchKey: "",
                orderState: "6,10",
                CanRefund: 1,
            },
            userId: 0,
        }
    },
    onLoad(e) {
        this.userId = e.userId
    },
    mounted() {
        this.getListHeight()
    },
    methods: {
        getListHeight(element) {
            //获取商品高度
            getElementHeight(this, ".main", (e) => {
                this.listHeight = e + "px"
                this.loadOk = true
                setTimeout((e) => {
                    this.refresh(this.requestData)
                }, 300)
            })
        },
        refresh(requestData) {
            this.param = requestData
            this.datas = []
            this.mescroll.resetUpScroll()
        },
        getData(page) {
            let param = this.requestData
            param.storeUserId = this.userId
            param.pageSize = page.size
            param.pageIndex = page.num
            param.orderState = this.requestData.orderState

            GetOrderPage(param).then((res) => {
                this.mescroll.endBySize(res.Data.length, res.RecordAmout)
                this.datas = this.datas.concat(res.Data)
            })
        },
        //搜索
        searchFn(searchKey) {
            this.requestData.searchKey = searchKey
            this.refresh()
        },
        //筛选
        doFilter(data) {
            this.requestData.startTime = data.startDate ? data.startDate + "T00:00:00.000Z" : ""
            this.requestData.endTime = data.endDate ? data.endDate + "T23:59:59.000Z" : ""
            this.refresh()
        },
        changeSearchValue(value) {
            //搜索关键字回调
            this.requestData.searchKey = value
        },
    },
}
</script>

<style lang="scss" scoped>
.container {
    display: flex;
    flex-direction: column;
}
</style>
